const js = require('@eslint/js')
const globals = require('globals')
const eslintParser = require('@babel/eslint-parser')
const eslintPretterPlugin = require('eslint-plugin-prettier')
<%_ if(language == supportedLanguage.typescript) { _%>
const tsParser = require('@typescript-eslint/parser')
const tsPlugin = require('@typescript-eslint/eslint-plugin')
<%_ } _%>
<%_ if (framework == supportedFramework.vue2 || framework == supportedFramework.vue3) { _%>
const vuePlugin = require('eslint-plugin-vue')
const vueParser = require('vue-eslint-parser')
<%_ } else if (framework == supportedFramework.react) { _%>
const reactHooks = require('eslint-plugin-react-hooks')
const reactPlugin = require('eslint-plugin-react')	
<%_ } _%>

module.exports = [
	// 忽略文件配置
	{
		ignores: ['node_modules/', 'dist/', 'test/', 'coverage/']
	},
	<%_ if(language == supportedLanguage.typescript) { _%>
	// TypeScript 配置
	{
		files: ['**/*.ts', <%- framework == supportedFramework.react ? '\'**/*.tsx\'' : ''-%>],
		plugins: {
			<%_ if (framework == supportedFramework.react) { _%>
				react: reactPlugin,
      			'react-hooks': reactHooks,
			<%_ } _%>
			prettier: eslintPretterPlugin,
			'@typescript-eslint': tsPlugin
		},
		languageOptions: {
			parser: tsParser,
			ecmaVersion: 'latest',
			parserOptions: {
				<%_ if(framework == supportedFramework.react) { _%>
				ecmaFeatures: {
					jsx: true
				},
				<%_ } _%>
				project: "./tsconfig.json"
			},
			sourceType: 'module',
			globals: { ...globals.browser, ...globals.node, ...globals.es2020 }
		},
		rules: {
			...tsPlugin.configs.recommended.rules,
			<%_ if(framework == supportedFramework.react) { _%>
			"react/jsx-uses-react": "error",
			"react/jsx-uses-vars": "error",
			"react/react-in-jsx-scope": "off",
			// React Hooks 规则
			"react-hooks/rules-of-hooks": "error",
			"react-hooks/exhaustive-deps": "warn",
			<%_ } _%>
			'@typescript-eslint/no-explicit-any': 'warn',
			'@typescript-eslint/explicit-function-return-type': 'off'
		}
	},
	<%_ } _%>
	<%_ if (framework == supportedFramework.vue2 || framework == supportedFramework.vue3) { _%>
	// Vue 文件配置
	{
		files: ['**/*.vue'],
		languageOptions: {
			parser: vueParser,
			parserOptions: {
				parser: <%= language == supportedLanguage.typescript ? 'tsParser' : 'eslintParser'%>,
				requireConfigFile: false,
				ecmaVersion: 'latest',
				sourceType: 'module'
			},
			globals: { ...globals.browser, ...globals.node }
			<%_ if (language == supportedLanguage.javascript) { _%>
			babelOptions: {
				presets: ['@babel/preset-env']
			}
			<%_ } _%>
		},
		plugins: {
			<%_ if (language == supportedLanguage.typescript) { _%>
			'@typescript-eslint': tsPlugin,
			<%_ } _%>
			vue: vuePlugin
		},
		rules: {
			<%_ if (language == supportedLanguage.typescript) { _%>
			...tsPlugin.configs.recommended.rules,
			<%_ } else { _%>
			...js.configs.recommended.rules,
			<%_ } _%>
			...vuePlugin.configs['flat/base'].rules,
			<%_ if (framework == supportedFramework.vue2) { _%>
			...vuePlugin.configs['flat/vue2-recommended'].rules,
			...vuePlugin.configs['flat/vue2-strongly-recommended'].rules,
			...vuePlugin.configs['flat/vue2-essential'].rules,
			<%_ } else { _%>
			...vuePlugin.configs['vue3-recommended'].rules,
			...vuePlugin.configs['vue3-strongly-recommended'].rules,
			...vuePlugin.configs['vue3-essential'].rules,
			<%_ } _%>
			'vue/multi-word-component-names': 'off',
			'vue/comment-directive': 'off',
			'vue/html-indent': 'off',
			'vue/max-attributes-per-line': 'off',
			'vue/require-default-prop': 'off',
			'vue/html-closing-bracket-newline': 'off',
			'vue/html-self-closing': [
				'error',
				{
					html: {
						void: 'always',
						normal: 'always',
						component: 'always'
					},
					svg: 'always',
					math: 'always'
				}
			]
		}
	},
	<%_ } _%>
	// 基础 JavaScript 配置
	{
		files: ['**/*.js', <%- framework == supportedFramework.react ? '\'**/*.jsx\'' : '' -%>],
		languageOptions: {
			ecmaVersion: 'latest',
			sourceType: 'module',
			parser: eslintParser,
			parserOptions: {
				requireConfigFile: false,
				<%_ if (framework == supportedFramework.react) { _%>
				ecmaFeatures: {
					jsx: true
				},
				<%_ } _%>
				babelOptions: {
					babelrc: false,
					configFile: false,
					presets: ['@babel/preset-env']
				}
			},
			globals: { ...globals.browser, ...globals.node, ...globals.es2020 }
		},
		plugins: {
			<%_ if (framework == supportedFramework.react) { _%>
				react: reactPlugin,
      			'react-hooks': reactHooks,
			<%_ } _%>
			prettier: eslintPretterPlugin
		},
		<%_ if (framework == supportedFramework.react) { _%>
		settings: {
			react: {
				version: "detect"
			}
		},
		<%_ } _%>
		rules: {
			...js.configs.recommended.rules,
			<%_ if(framework == supportedFramework.react) { _%>
			"react/jsx-uses-react": "error",
			"react/jsx-uses-vars": "error",
			"react/react-in-jsx-scope": "off",
			// React Hooks 规则
			"react-hooks/rules-of-hooks": "error",
			"react-hooks/exhaustive-deps": "warn",
			<%_ } _%>
			'prettier/prettier': [
				'error',
				{
					singleQuote: true,
					semi: false
				}
			],
			'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
			'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
		}
	}
]
